home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / Interapplication Communication / MenuScripter 4.0 / Sources / MSFile.c < prev    next >
Encoding:
Text File  |  1996-07-09  |  16.5 KB  |  758 lines  |  [TEXT/CWIE]

  1. // MSFile.c
  2. //
  3. // Original version by Jon Lansdell and Nigel Humphreys.
  4. // 4.0 and 3.1 updates by Greg Sutton.
  5. // ©Apple Computer Inc 1996, all rights reserved.
  6.  
  7. /*
  8.     Changes for 4.0
  9.  
  10.     28-Feb-96 : GS : Added script to document file. This script is attached to the document
  11.                         and gets first go at handling Apple events targetted at the document.
  12. */
  13.  
  14. #include <Errors.h>
  15. #include <Resources.h>
  16. #include <Desk.h>
  17. #ifdef THINK_C
  18.     #include "PLStrs.h"
  19. #else
  20.     #include <PLStringFuncs.h>
  21. #endif
  22. #include <AppleEvents.h>
  23. #include <AERegistry.h>
  24. #include <StandardFile.h>
  25. #include "MSFile.h"
  26. #include "Offscreen.h"
  27. #include "MSResultWind.h"
  28. #include "MSAEWindowUtils.h"
  29. #include "MSScript.h"
  30. #include "MSAESetData.h"
  31.  
  32. #include <LowMem.h>
  33.  
  34.     // Constants
  35. const    OSType    kStyleInfoType        = 'TFSF';
  36. const    OSType    kHeaderInfoType        = 'TFSS';
  37. const    OSType    kGXPrinterInfoType    = 'TFGX';
  38.  
  39.  
  40. //    Name:             FileError
  41. //    Purpose:        Puts up an error alert.
  42.  
  43. #pragma segment File
  44.  
  45. void    FileError( Str255 s, Str255 f )
  46. {
  47.     short    alertResult;
  48.     
  49.     SetCursor(&qd.arrow);
  50.     ParamText(s, f, (unsigned char *)"", (unsigned char *)"");
  51.     alertResult = Alert( ErrorAlert, NULL );
  52. }
  53.  
  54. //    Name:             DoClose
  55. //    Purpose:        Closes a window.
  56.  
  57. #pragma segment File
  58.  
  59. OSErr    DoClose( WindowPtr aWindow,Boolean canInteract,DescType dialogAnswer )
  60. {
  61.     DPtr    aDocument;
  62.     short   alertResult;
  63.     OSErr   myErr;
  64.                         
  65.     myErr = noErr;
  66.         
  67.     aDocument = DPtrFromWindowPtr(aWindow);
  68.     if ( ! aDocument )
  69.         return noErr;
  70.         
  71. // Save if the windows contents have changed and it's not the results window
  72.     if ((aDocument->dirty) && !IsThisResultWind(aWindow))
  73.     {
  74.         if (canInteract && (dialogAnswer==kAEAsk))
  75.         {
  76.             alertResult = DoFileDialog ( kSaveDontsaveDialog, aWindow );
  77.             switch ( alertResult )
  78.             {
  79.                 case kStdOkItemIndex:
  80.                     if (aDocument->everSaved == false)
  81.                     {
  82.                         myErr = GetFileNameToSaveAs(aDocument);
  83.                         if (myErr == noErr)
  84.                             myErr = DoSave(aDocument, aDocument->theFSSpec);
  85.                     }
  86.                     else
  87.                         myErr = SaveUsingTemp(aDocument);
  88.                 break;
  89.                                                             
  90.                 case kStdCancelItemIndex:
  91.                     return(userCanceledErr);
  92.                 break;
  93.                 
  94.                 case kDontSaveItemIndex:
  95.                     aDocument->dirty = false;
  96.                 break;
  97.             }
  98.         }
  99.         else
  100.         {
  101.             if (dialogAnswer==kAEYes)
  102.                 if (aDocument->everSaved == false)
  103.                 {
  104.                     if (canInteract)
  105.                     {
  106.                         myErr = GetFileNameToSaveAs(aDocument);
  107.                         if (myErr==noErr)
  108.                             myErr = DoSave(aDocument, aDocument->theFSSpec);
  109.                     }
  110.                     else    
  111.                         return(errAENoUserInteraction);
  112.                 }
  113.                 else
  114.                     myErr = SaveUsingTemp(aDocument);
  115.             else
  116.                 myErr = noErr; // Don't save
  117.         }
  118.     }
  119.             
  120.     if ( myErr == noErr )
  121.         CloseMyWindow(aWindow);
  122.             
  123.     return(myErr);
  124. }
  125.  
  126.  
  127. // This is called to display the "save before closing" and "revert" dialogs.
  128.  
  129. short    DoFileDialog( short theDlogID, WindowRef theWindow )
  130. {
  131.     short        theItem;
  132.     DialogRef    theDialog;
  133.     WindowRef    dialogWindow;
  134.     DPtr        theDocument;
  135.     Str255        theTitle, theReason;
  136.     
  137.     
  138.     theDocument = DPtrFromWindowPtr ( theWindow );
  139.     
  140.     theDialog = GetNewDialog ( theDlogID, nil, (WindowRef) -1 );
  141.     dialogWindow = GetDialogWindow ( theDialog );
  142.     SetPortWindowPort ( dialogWindow );
  143.     
  144.     
  145.     if ( theDocument->everSaved == false )
  146.         GetWTitle ( theWindow, theTitle );         // Pick it up as a script may have changed it
  147.     else
  148.         PLstrcpy ( theTitle, theDocument->theFileName );
  149.     
  150.     if ( gQuitting )
  151.         GetIndString ( theReason, kMiscStrings, kQuittingIndex );
  152.     else
  153.         GetIndString ( theReason, kMiscStrings, kClosingindex );
  154.     
  155.     SetCursor ( &qd.arrow );
  156.     ParamText ( theTitle, theReason, nil, nil );
  157.     ShowMSWindow ( dialogWindow );
  158.     SelectWindow ( dialogWindow );
  159.     
  160.     SetDialogDefaultItem ( theDialog, kStdOkItemIndex );
  161.     SetDialogCancelItem ( theDialog, kStdCancelItemIndex );
  162.     
  163.     // As long as the only enabled items are the dimissers, 
  164.     // there is no need to call ModalDialog within a loop.
  165.     ModalDialog ( nil, &theItem );
  166.     DisposeDialog ( theDialog );
  167.     
  168.     return theItem;
  169. }        
  170.  
  171.  
  172. #pragma segment File
  173.  
  174. //  DoQuit
  175. //  saveOpt - one of kAEAsk,kAEYes,kAENo
  176. //  if kAEYes or kAEAsk then AEInteactWithUser should have been called
  177. //  before DoQuit. Assumes that it can interact if it needs to.
  178.  
  179. void    DoQuit( DescType saveOpt )
  180. {
  181.     WindowPtr    aWindow;
  182.     WindowPtr    nextWindow;
  183.     WindowPeek   nextWPeek;
  184.     short        theKind;
  185.     OSErr        check;
  186.     
  187.     aWindow = (WindowPtr)LMGetWindowList();
  188.     
  189.     gQuitting = true;
  190.     while ( aWindow )
  191.     {
  192.         nextWPeek  = ((WindowPeek)aWindow)->nextWindow;
  193.         nextWindow = &nextWPeek->port;
  194.         if (Ours(aWindow))
  195.         {
  196.             check = DoClose(aWindow, true, saveOpt);
  197.             if ( check != noErr )
  198.             {
  199.                 gQuitting = false;
  200.                 return;
  201.             }
  202.         }
  203.         else
  204.         {
  205.             theKind = ((WindowPeek)aWindow)->windowKind;
  206.             if (theKind < 0)
  207.                 CloseDeskAcc(theKind);
  208.         }
  209.         aWindow = nextWindow;
  210.     }
  211. } // DoQuit
  212.  
  213.  
  214. OSErr    GetFile( FSSpec *theFSSpec )
  215. {
  216.     SFTypeList         myTypes;
  217.     StandardFileReply  reply;
  218.     
  219.     myTypes[0] = 'TEXT';
  220.     
  221.     StandardGetFile( NULL, 1, myTypes, &reply );
  222.     
  223.     if (reply.sfGood)
  224.     {
  225.         *theFSSpec = reply.sfFile;
  226.         return(noErr);
  227.     }
  228.     else
  229.         return(userCanceledErr);
  230. }
  231.  
  232.  
  233. #pragma segment File
  234.  
  235. OSErr    DoCreate( FSSpec theSpec )
  236. {
  237.     OSErr err;
  238.     
  239.     err = FSpCreate(&theSpec, MenuScripterAppSig, 'TEXT', smSystemScript);
  240.     
  241.     if (err != noErr)
  242.          ShowError((unsigned char *)"\pDoCreate", err);
  243.             
  244.     return(err);
  245. }
  246.  
  247.  
  248. #pragma segment File
  249.  
  250. OSErr    WriteFile( DPtr theDocument, short refNum, FSSpec theFSSpec )
  251. {
  252.     short        resFile;
  253.     long         length;
  254.     HHandle      theHHandle;
  255.     StScrpHandle theSHandle;
  256.     OSErr        err;
  257.     StringHandle theAppName;
  258.     short        oldSelStart;
  259.     short        oldSelEnd;
  260.     Handle       thePHandle;
  261.     Handle       myText;
  262.     Handle       thePGXHandle;
  263.     
  264.     tWindowOffscreen*    theOffscreen = nil;
  265.     
  266.     // first write out the text to the data fork
  267.         
  268.     length = (*(theDocument->theText))->teLength;
  269.     myText = (*(theDocument->theText))->hText;
  270.         
  271.     HLock( myText );
  272.     
  273.     err = FSWrite(refNum, &length, *myText);
  274.     if ( noErr != err )
  275.         return err;
  276.             
  277.     HUnlock( myText );
  278.     
  279.         // we are writing to a temporary file, so we need to create the resource file
  280.         // before writing out the resources
  281.         // now open the resource file
  282.         
  283.     HCreateResFile(theFSSpec.vRefNum, theFSSpec.parID, theFSSpec.name);
  284.     err = ResError();
  285.     if (err)
  286.     {
  287.         ShowError((unsigned char *)"\pHCreateResFile", err);
  288.         return(err);
  289.     }
  290.     
  291.     resFile = HOpenResFile( theFSSpec.vRefNum, theFSSpec.parID, theFSSpec.name, fsWrPerm );
  292.     err = ResError();
  293.     
  294.     if (err)
  295.     {
  296.         ShowError((unsigned char *)"\pHOpenResFile", err);
  297.         return(err);
  298.     }
  299.     
  300.     // Write out our 'TFSF' resource to file
  301.      
  302.     //    Draw everything into offscreen pixmap.
  303.     theOffscreen = DrawOffscreen ( theDocument->theWindow );
  304.     if ( theOffscreen  )
  305.         (*theDocument->theText)->inPort = (GrafPtr) theOffscreen->offscreenWorld;
  306.     
  307.     
  308.     oldSelStart = (*(theDocument->theText))->selStart;
  309.     oldSelEnd   = (*(theDocument->theText))->selEnd;
  310.     TESetSelect( 0, kMaxTELength, theDocument->theText );
  311.     
  312.     theSHandle = TEGetStyleScrapHandle(theDocument->theText);
  313.     
  314.     TESetSelect(oldSelStart,oldSelEnd, theDocument->theText);
  315.     
  316.     
  317.     if ( theOffscreen )
  318.     {
  319.         // If it wasn't for the caret, we wouldn't need to draw this
  320.         theOffscreen = DrawOnscreen ( theOffscreen );
  321.         (*theDocument->theText)->inPort = theDocument->theWindow;
  322.     }
  323.     
  324.     AddResource((Handle)theSHandle, kStyleInfoType, 255, (unsigned char *)"\pStyle Info");
  325.     err = ResError();
  326.     if (err)
  327.     {
  328.         ShowError((unsigned char *)"\pAddResource - Style Info", err);
  329.         return(err);
  330.     }
  331.                     
  332.     // Write out the printer info
  333.                 
  334.     // First the QD info
  335.                 
  336.     if (theDocument->thePrintSetup)
  337.     {
  338.         thePHandle = (Handle)theDocument->thePrintSetup;
  339.         err = HandToHand(&thePHandle);
  340.         
  341.         AddResource(thePHandle, 'TFSP', 255, (unsigned char *)"\pPrinter Info");
  342.         err = ResError();
  343.         if (err)
  344.             {
  345.                 ShowError((unsigned char *)"\pAddResource- TFSP", err);
  346.                 return(err);
  347.             }
  348.     }
  349.                 
  350.     // Next the QD QX info
  351.     if ( ( gGXIsPresent ) && ( theDocument->documentJob ) )
  352.     {
  353.         thePGXHandle = NewHandle(0);
  354.         GXFlattenJobToHdl(theDocument->documentJob, thePGXHandle);
  355.     
  356.         AddResource(thePGXHandle, kGXPrinterInfoType, 255, (unsigned char *)"\pGX Printer Info");
  357.         err = ResError();
  358.         if (err)
  359.         {
  360.             ShowError((unsigned char *)"\pAddResource- TFGX", err);
  361.             return(err);
  362.         }
  363.     }
  364.                 
  365.     theHHandle = (HHandle)NewHandle(sizeof(HeaderRec));
  366.     HLock((Handle)theHHandle);
  367.     
  368.     GetFontName(theDocument->theFont, (unsigned char *)&(*theHHandle)->theFont);
  369.     (*theHHandle)->theSize     = theDocument->theSize;
  370.     (*theHHandle)->theStyle    = theDocument->theStyle;
  371.     (*theHHandle)->lastID      = 0;
  372.     
  373.     HUnlock((Handle)theHHandle);
  374.     
  375.     AddResource((Handle)theHHandle, kHeaderInfoType, 255, (unsigned char *)"\pHeader Info");
  376.     
  377.     err = ResError();
  378.     if (err)
  379.     {
  380.         ShowError((unsigned char *)"\pAddResource- Header Info", err);
  381.         return(err);
  382.     }
  383.     
  384.     // Now put an AppName in for Finder in 7.0
  385.     
  386.     theAppName = (StringHandle)NewHandle(gAppRec.theName[0]);
  387.     PLstrcpy( *theAppName, gAppRec.theName );
  388.     
  389.     AddResource((Handle)theAppName, 'STR ', -16396, (unsigned char *)"\pFinder App Info");
  390.     
  391.     err = ResError();
  392.     
  393.     if (err)
  394.     {
  395.         ShowError((unsigned char *)"\pAppName", err);
  396.         return(err);
  397.     }
  398.     
  399.         // Each document has a script associated with it
  400.         //  this can be changed so store in resource.
  401.     err = StoreDocumentScript( theDocument, resFile );
  402.     
  403.     CloseResFile( resFile );
  404.     
  405.     return err;
  406. } // WriteFile
  407.  
  408.  
  409. #pragma segment File
  410.  
  411. OSErr    ReadFile( DPtr theDocument, short  refNum, Str255 fn )
  412. {
  413.     long            theSize;
  414.     short           resFile;
  415.     OSErr           err;
  416.     HHandle         aHandle;
  417.     Handle          gHandle;
  418.     Handle          hGXJobData;
  419.     Boolean         gotQDPrintRec;
  420.     
  421.     gotQDPrintRec = false;
  422.     
  423.     err = GetEOF(refNum, &theSize);
  424.     if (err)
  425.         return(err);
  426.     
  427.     // We're only using TE, so check that there is not more than 32K worth of text
  428.             
  429.     if (theSize > kMaxTELength)
  430.       return(1);
  431.     
  432.     gHandle = NewHandle(theSize);
  433.     HLock(gHandle);
  434.     err = FSRead(refNum, &theSize, *gHandle);
  435.             
  436.     if (err)
  437.     {
  438.         HUnlock(gHandle);
  439.         return(err);
  440.     }
  441.                             
  442.     resFile = HOpenResFile(theDocument->theFSSpec.vRefNum, 
  443.                                                  theDocument->theFSSpec.parID,
  444.                                                  fn,
  445.                                                  fsWrPerm);
  446.     if ( resFile == -1 )
  447.         err = fnfErr;
  448.                 
  449.     if ( err == noErr )
  450.     {
  451.         aHandle = NULL;
  452.  
  453.         if ( Count1Resources( kHeaderInfoType ) )
  454.             aHandle = (HHandle)Get1Resource( kHeaderInfoType, 255 );
  455.  
  456.         //    New Format Info
  457.  
  458.         aHandle = nil;
  459.         
  460.         if ( Count1Resources( kStyleInfoType ) )
  461.             aHandle = (HHandle)Get1Resource( kStyleInfoType, 255 );
  462.             
  463.         HLock(gHandle);
  464.         TEStylInsert( *gHandle, GetHandleSize(gHandle),
  465.                             (StScrpHandle)aHandle, theDocument->theText );
  466.         HUnlock(gHandle);
  467.         
  468.         //    If there is a print record saved, ditch the old one
  469.         //    created by new document and fill this one in
  470.  
  471.         if (Count1Resources('TFSP'))
  472.         {
  473.             if (theDocument->thePrintSetup)
  474.                 DisposHandle((Handle)theDocument->thePrintSetup);
  475.             
  476.             theDocument->thePrintSetup = (THPrint)Get1Resource('TFSP', 255);
  477.               err = HandToHand((Handle *)&theDocument->thePrintSetup);
  478.             
  479.             gotQDPrintRec = true;
  480.             if (! gGXIsPresent)
  481.                 PrValidate(theDocument->thePrintSetup);
  482.         }
  483.  
  484.         if ( gGXIsPresent )
  485.             if ( Count1Resources( kGXPrinterInfoType ) )
  486.             {
  487.                 if (theDocument->documentJob)
  488.                 {
  489. //                        GXDisposeJob(theDocument->documentJob);
  490. //                        theDocument->documentJob = nil;
  491.                 }
  492.  
  493.                 hGXJobData = Get1Resource( kGXPrinterInfoType, 255 );
  494.  
  495.                 if (hGXJobData)
  496.                 {
  497.                     GXUnflattenJobFromHdl(theDocument->documentJob, hGXJobData);
  498.                     err = GXGetJobError(theDocument->documentJob);
  499.                     ReleaseResource(hGXJobData);
  500.                 }
  501.             }
  502.             else
  503.             {
  504.                 if (gotQDPrintRec)
  505.                     GXConvertPrintRecord(theDocument->documentJob, theDocument->thePrintSetup);
  506.             }
  507.             
  508.         err = LoadDocumentScript( theDocument, resFile );
  509.  
  510.         CloseResFile(resFile);
  511.  
  512.         err = ResError();
  513.         if (err)
  514.         {
  515.             ShowError((unsigned char *)"\pReadFile - CloseResFile", err);
  516.             return(err);
  517.         }
  518.     }
  519.     else
  520.         TESetText( *gHandle, GetHandleSize(gHandle), theDocument->theText );
  521.         
  522.     if (gHandle)
  523.         DisposHandle(gHandle);
  524.         
  525.     if (err==fnfErr)
  526.         err = noErr;
  527.     
  528.     return(err);
  529. } // ReadFile
  530.  
  531.  
  532. //    Name:             GetFileContents
  533. //    Purpose:        Opens the document specified by theFSSpec and puts
  534. //                     the contents into theDocument.
  535.     
  536. #pragma segment File
  537.  
  538. OSErr    GetFileContents( FSSpec theFSSpec, DPtr theDocument )
  539. {
  540.     OSErr    err;
  541.     short    theRefNum;
  542.  
  543.     // this can be called from two places- on an OpenDoc AppleEvent
  544.     // and by the user just selecting Open from the File Menu
  545.     // assume that the CFS is correct when the routine is called
  546.  
  547.     err = FSpOpenDF( &theFSSpec, fsRdWrPerm, &theRefNum );
  548.     if (err)
  549.     {
  550.         ShowError((unsigned char *)"\pFSpOpenDF", err);
  551.         return(err);
  552.     }
  553.     else
  554.     {
  555.         err = ReadFile(theDocument, theRefNum, theFSSpec.name);
  556.         if (err)
  557.         {
  558.             ShowError((unsigned char *)"\pReadFile", err);
  559.             return(err);
  560.         }
  561.         err=FSClose(theRefNum);
  562.         if (err)
  563.         {
  564.             ShowError((unsigned char *)"\pFSClose", err);
  565.             return(err);
  566.         }
  567.         return(noErr);
  568.     }
  569. }
  570.  
  571.     
  572. #pragma segment File
  573.  
  574. OSErr    SaveUsingTemp( DPtr theDocument )
  575. {
  576.     Str255        tempName;
  577.     FSSpec        tempFSSpec;
  578.     OSErr        err;
  579.     
  580.     // save the file to disk using a temporary file
  581.     // this is the recommended way of doing things
  582.     // first write out the file to disk using a temporary filename
  583.     // if it is sucessfully written, exchange the temporary file with the last one saved
  584.     // then delete the temporary file- so if anything goes wrong, the original version is still there
  585.     // first generate the temporary filename
  586.     
  587.     GetTempFileName(theDocument, tempName);
  588.  
  589.     //create this file on disk
  590.     
  591.     tempFSSpec = theDocument->theFSSpec;
  592.     PLstrcpy( tempFSSpec.name, tempName );
  593.         
  594.     err = DoCreate(tempFSSpec);    
  595.     
  596.     // now save the file as normal
  597.     
  598.     if (err == noErr)
  599.         err = DoSave(theDocument, tempFSSpec);
  600.     
  601.     if (err == noErr)
  602.         err = FSpExchangeFiles(&tempFSSpec, &theDocument->theFSSpec);
  603.     
  604.     // we've exchanged the files, now delete the temporary one
  605.     
  606.     if (err == noErr)
  607.       err = FSpDelete(&tempFSSpec);
  608.     
  609.     return(err);
  610. }
  611.  
  612.     
  613. #pragma segment File
  614.  
  615. //    Fills in the document record with the user chosen destination
  616.  
  617. OSErr    GetFileNameToSaveAs(DPtr theDocument)
  618. {            
  619.     StandardFileReply   reply;
  620.     OSErr               err;
  621.     Str255              suggestName;
  622.     
  623.     GetWTitle(theDocument->theWindow, suggestName);
  624.     
  625.     StandardPutFile((unsigned char *)"\pSave Document As:", suggestName, &reply);
  626.     
  627.     if (reply.sfGood)
  628.     {                
  629.         err = FSpDelete(&reply.sfFile);
  630.         
  631.         if (!((err==noErr) || (err==fnfErr)))
  632.             return(err);
  633.         else
  634.             err = noErr;
  635.             
  636.         theDocument->theFSSpec = reply.sfFile;
  637.         PLstrcpy(theDocument->theFileName, reply.sfFile.name);
  638.     }
  639.     else
  640.         err = userCanceledErr;
  641.     
  642.     return(err);
  643. } // GetFileNameToSaveAs
  644.  
  645.     
  646. #pragma segment File
  647.  
  648. OSErr    DoSave( DPtr theDocument, FSSpec theFSSpec )
  649. {
  650.     short      refNum;
  651.     OSErr      fileErr;
  652.     
  653.     fileErr = FSpOpenDF(&theFSSpec, fsRdWrPerm, &refNum);
  654.     
  655.     if (fileErr == fnfErr)
  656.     {
  657.       fileErr = DoCreate(theFSSpec);
  658.         
  659.         if (fileErr)
  660.             return(fileErr);
  661.             
  662.         fileErr = FSpOpenDF(&theFSSpec, fsRdWrPerm, &refNum);
  663.     }
  664.     
  665.     if (fileErr == noErr)
  666.     {
  667.       fileErr = WriteFile(theDocument, refNum, theFSSpec);
  668.         
  669.         if (fileErr==noErr)
  670.             theDocument->dirty = false;
  671.             
  672.         fileErr = FSClose(refNum);
  673.     }
  674.     else
  675.         FileError((unsigned char *)"\perror opening file ", theFSSpec.name);
  676.     
  677.     return(fileErr);
  678. }
  679.  
  680.     
  681. #pragma segment File
  682.  
  683. OSErr    OpenOld( FSSpec aFSSpec )
  684. {        
  685.     DPtr              aDocument;
  686.     AEDesc            aDesc = { typeNull, NULL },
  687.                     aBoundsDesc = { typeNull, NULL };
  688.     WindowPropToken    aPropToken;
  689.     Str255            aPStr;
  690.     OSErr            anErr;
  691.     
  692.     aDocument = NewDocument( true, (WindowPtr)-1L );
  693.     
  694.     SetWTitle( aDocument->theWindow, aFSSpec.name );
  695.     
  696.     SetPort( aDocument->theWindow );
  697.     
  698.     aDocument->theFSSpec   = aFSSpec;
  699.     
  700.     PLstrcpy( aDocument->theFileName,aFSSpec.name );
  701.     
  702.     aDocument->dirty       = false;
  703.     aDocument->everSaved   = true;
  704.     
  705.     anErr = GetFileContents( aFSSpec, aDocument );
  706.     
  707.     if ( noErr == anErr )
  708.     {            // Try and get the saved script property
  709.         if ( kOSANullScript != aDocument->theScriptID )
  710.         {
  711.             PLstrcpy( aPStr, "\pwindowbounds" );
  712.             anErr = AECreateDesc( typeChar, (Ptr)&aPStr[1], aPStr[0], &aDesc );
  713.             if ( noErr != anErr ) goto done;
  714.             
  715.             anErr = GetScriptProperty( aDocument->theScriptID, &aDesc, &aBoundsDesc );
  716.             if ( noErr == anErr )
  717.             {        // Set up a token for the document
  718.                 aPropToken.tokenWindowToken.tokenWindow = aDocument->theWindow;
  719.                 aPropToken.tokenProperty = pBounds;
  720.             
  721.                 anErr = SetDocumentTokenProperty( &aPropToken, &aBoundsDesc );
  722.             }
  723.             else
  724.                 anErr = noErr;    // Script does not have this property
  725.         }
  726.     
  727.         ResizeWindow( aDocument );
  728.         SelectWindow( aDocument->theWindow );
  729.         ShowMSWindow( aDocument->theWindow );
  730.     }
  731.     else
  732.         FileError( (unsigned char *)"\pError Opening ", aFSSpec.name );
  733.  
  734. done:
  735.     (void)AEDisposeDesc( &aDesc );
  736.     (void)AEDisposeDesc( &aBoundsDesc );
  737.     
  738.     return anErr;
  739. } // OpenOld
  740.  
  741. /*   
  742. #pragma segment File
  743.  
  744. OSErr    OpenUsingAlias( AliasHandle theAliasH )
  745. {
  746.     OSErr    err;
  747.     FSSpec   aFSSpec;
  748.     Boolean  dummy;
  749.     
  750.     err = ResolveAlias(nil, theAliasH, &aFSSpec, &dummy);
  751.     
  752.     if (err == noErr)
  753.         err = OpenOld(aFSSpec);
  754.                 
  755.     return(err);
  756. }
  757. */
  758.